//
//  ClassifyVC.m
//  SYPerfectDemo
//
//  Created by Lssyyy on 2018/4/26.
//  Copyright © 2018年 Lssyyy. All rights reserved.
//

#import "ClassifyVC.h"
#import "LogicTableViewVC.h"
#import "ClassifyCell.h"
#import "CustomUITableViewVC.h"
#import "KnowledgePointVC.h"
static NSString *keykey = @"cellKey";
@interface ClassifyVC ()
@property (nonatomic,strong) NSMutableArray *titleArray;
@end

@implementation ClassifyVC

- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"这是我在分支开发的功能");
    
}

//- (void)addUI{
//    [super addUI];
//}
//
//- (void)layoutUI{
//    [super layoutUI];
//}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
}

- (void)config{
     [self.tableView registerClass:[ClassifyCell class] forCellReuseIdentifier:@"ClassifyCell"];
    [self.titleArray addObjectsFromArray:[NSArray arrayWithObjects:@"逻辑类",@"UI类",@"知识点", nil]];
    [self.tableView reloadData];
}

- (void)refreshMethod{
    [self.refreshHeader endRefreshing];
}

- (void)loadMoreMethod{
    [self.refreshFooter endRefreshing];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _titleArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ClassifyCell *cell = [ClassifyCell dequeueCellWithTableView:tableView indexPath:indexPath];
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressMethod:)];
    [cell addGestureRecognizer:longPress];
    objc_setAssociatedObject(longPress, &keykey, indexPath, OBJC_ASSOCIATION_RETAIN_NONATOMIC);

    [cell configContent:_titleArray[indexPath.row]];
    return cell;
}

- (void)longPressMethod:(UILongPressGestureRecognizer *)gesture{
   NSIndexPath *indexPath = objc_getAssociatedObject(gesture, &keykey);
    NSLog(@"绑定的%ld",indexPath.row);
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewAutomaticDimension;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.row) {
        case 0:{
            LogicTableViewVC *vc = [[LogicTableViewVC alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
            break;
        }
        case 1:{
            CustomUITableViewVC *vc = [[CustomUITableViewVC alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
            break;
        }
        case 2:{
            KnowledgePointVC *vc = [[KnowledgePointVC alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
            break;
        }
        default:
            break;
    }
    
}


- (NSMutableArray *)titleArray{
    if (!_titleArray) {
        _titleArray = [NSMutableArray array];
    }
    return _titleArray;
}
@end
